home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / ead / ead23.dms / ead23.adf / Listati / FileBootBlock.asm < prev    next >
Assembly Source File  |  1990-05-29  |  11KB  |  298 lines

  1. *****************************************************************************
  2. *                                                                           *
  3. * Programma ....... FileBootBlock.asm                                       *
  4. *                                                                           *
  5. * Autore .......... John Veldthuis, New Zealand                             *
  6. *                                                                           *
  7. * Versione ........ 1.00i, 22 Novembre 1988, 29 Maggio 1990                 *
  8. *                                                                           *
  9. * Scopo ........... Trasformare bootblock in file e viceversa               *
  10. *                                                                           *
  11. * Software ........ Devpac HiSoft V2.14                                     *
  12. *                                                                           *
  13. * Hardware ........ Amiga 500/1000/2000/2500, Kickstart & Workbench 1.2/1.3 *
  14. *                                                                           *
  15. * Note ............ Traduzione ed adattamento per EAD di Luigi Callegari    *
  16. *                                                                           *
  17. *****************************************************************************
  18.  
  19.           incdir   "dh1:Includedevpac/"    ; Modificare per propria directory
  20.           
  21.           include  "exec/types.i"
  22.           include  "intuition/intuition.i"
  23.           include  "devices/trackdisk.i"
  24.           include  "exec/memory.i"
  25.           include  "libraries/dosextens.i"
  26.           include  "libraries/dos_lib.i"
  27.           include  "intuition/intuition_lib.i"
  28.           include  "exec/exec_lib.i"
  29.  
  30. Offsets   macro
  31. \1        equ   soffset
  32. soffset   set   soffset+\2
  33.           endm
  34. soffset   set   0
  35.  
  36.           Offsets  dosbase,4
  37.           Offsets  execbase,4
  38.           Offsets  filehandle,4
  39.           Offsets  buffer,4
  40.           Offsets  port,4
  41.           Offsets  filename,4
  42.           Offsets  diskreq,4
  43.           Offsets  task,4
  44.           Offsets  mementry,4
  45.           Offsets  unit,4
  46.           Offsets  stdout,4
  47.  
  48. Start:
  49.           lea      BASE(pc),a5
  50.           move.l   4.w,a6
  51.           move.l   a6,execbase(a5)
  52.           movem.l  d0/a0,-(sp)
  53.           move.l   $114(a6),a0           ; Trova questo task
  54.           move.l   a0,task(a5)
  55.           move.l   pr_COS(a0),stdout(a5) ; Salva stream di output per mess.
  56.           moveq.l  #33,d0                ; Almeno Kickstart V1.2
  57.           lea      DosLib(pc),a1
  58.           jsr      _LVOOpenLibrary(a6)   ; Apre DOS.library
  59.           movem.l  (sp)+,d1/a0
  60.           tst.l    d0
  61.           bne.s    Lib1
  62. NoLib     moveq.l   #20,d0               ; Manca libreria, fermati e segnala
  63.           rts                            ; Torna a casa, Lassie!
  64. Lib1      move.l   d0,dosbase(a5)
  65.           moveq    #0,d0
  66.           move.b   d0,-1(a0,d1.w)        ; Marca fine della linea Shell
  67. 1$        move.b   (a0)+,d0
  68.           beq      CLIErr
  69.           and.b    #%11011111,d0         ; Trasforma in maiuscolo
  70.           cmp.b    #'D',d0               ; Cerca la D in DFn
  71.           bne.s    1$
  72.           move.b   (a0)+,d0              ; Fittizio, per saltare la F
  73.           move.b   (a0)+,d0              ; Legge il numero di unità
  74.           sub.b    #'0',d0               ; Trasforma in numero reale
  75.           ext.w    d0                    ; Estende a dimensione parola
  76.           ext.l    d0                    ; Estende a dimensione longword
  77.           move.l   d0,unit(a5)           ; Salva numero di unita'
  78. 2$        move.b   (a0)+,d0              ; Cerca la spaziatura
  79.           cmp.b    #' ',d0
  80.           bne.s    2$
  81.           move.l   a0,filename(a5)       ; Salva indirizzo nomefile
  82.           lea      Mem(pc),a0
  83.           jsr      _LVOAllocEntry(a6)    ; Alloca tutta la memoria in una volta
  84.           btst     #31,d0
  85.           bne      MemErr                ; Bit 31 disattivo, errata memoria
  86.           move.l   d0,mementry(a5)       ; Salva per successivo rilascio
  87.           move.l   d0,a0
  88.           add.w    #Mem1-Mem,a0
  89.           move.l   (a0),buffer(a5)       ; Salva indirizzo buffer di I/O
  90.           bsr      CreatePort            ; Crea porta di risposta
  91.           tst.l    d0
  92.           beq      PError                ; Nessuna porta di risposta
  93.           move.l   d0,d3
  94.           move.l   d0,port(a5)           ; Salva per successiva chiusura
  95.           move.l   mementry(a5),a0
  96.           add.w    #Mem2-Mem,a0
  97.           move.l   (a0),a0               ; Crea un blocco IORequest
  98.           move.b   #NT_MESSAGE,LN_TYPE(a0)
  99.           move.w   #IOSTD_SIZE,MN_LENGTH(a0)
  100.           move.l   d3,MN_REPLYPORT(a0)
  101.           move.l   a0,diskreq(a5)        ; Salva indirizzo blocco IO
  102.           move.l   unit(a5),d0
  103.           lea      TrackName(pc),a0
  104.           move.l   diskreq(a5),a1
  105.           moveq.l  #0,d1
  106.           jsr      _LVOOpenDevice(a6)    ; Apre trackdisk su unità
  107.           tst.l    d0
  108.           bgt      TErr                  ; Non s'apre, mostra errore
  109.           move.l   diskreq(a5),a1
  110.           move.w   #CMD_READ,IO_COMMAND(a1)
  111.           move.l   buffer(a5),IO_DATA(a1)
  112.           move.l   #1024,IO_LENGTH(a1)
  113.           move.l   #0,IO_OFFSET(a1)
  114.           jsr      _LVODoIO(a6)          ; Legge bootblock nel buffer
  115.           move.l   diskreq(a5),a1
  116.           move.w   #TD_MOTOR,IO_COMMAND(a1)
  117.           move.l   #0,IO_LENGTH(a1)
  118.           jsr      _LVODoIO(a6)          ; Spegne il motore
  119.           move.l   diskreq(a5),a1
  120.           move.b   IO_ERROR(a1),d3       ; Controlla se c'era errore
  121.           jsr      _LVOCloseDevice(a6)   ; Chiude il trackdisk.device
  122.           cmp.b    #19,d3
  123.           bgt      ReadErr               ; Se errore, mostralo
  124.           move.l   buffer(a5),a0
  125.           move.w   #$600A,(a0)           ; Cambia primo bytes in BRA.s *+$C
  126.                                          ; per non alterare indirizzo relativo
  127.           move.l   dosbase(a5),a6        ; Legge DOSBase
  128.           move.l   filename(a5),d1
  129.           move.l   #MODE_NEWFILE,d2
  130.           jsr      _LVOOpen(a6)          ; Apre file dove mettere bootblock
  131.           tst.l    d0
  132.           beq      OpenErr               ; Non s'è aperto per qualche motivo
  133.           move.l   d0,filehandle(a5)     ; Salva handler per la chiusura
  134.           lea      table(pc),a0          ; Legge prima parte del file
  135.           move.l   a0,d2                 ; Usato per creare un file di programma
  136.           move.l   d0,d1                 ; Filehandle in D1
  137.           moveq    #32,d3                ; Lunghezza dei numeri
  138.           jsr      _LVOWrite(a6)
  139.  
  140.           cmp.l    #32,d0
  141.           bne      WriteErr
  142.           move.l   buffer(a5),d2
  143.           move.l   filehandle(a5),d1
  144.           move.l   #1024,d3
  145.           jsr      _LVOWrite(a6)         ; Scrive il resto del file
  146.           cmp.l    #1024,d0              ; Controllando se tutto OK
  147.           bne.s    WriteErr
  148.  
  149.           move.l   filehandle(a5),d1
  150.           lea      hunkend(pc),a0
  151.           move.l   a0,d2
  152.           moveq    #4,d3
  153.           jsr      _LVOWrite(a6)         ; Scvrive ultimo pezzetto del file
  154.           cmp.l    #4,d0
  155.           bne.s    WriteErr
  156. Fin       move.l   filehandle(a5),d1
  157.           tst.l    d1
  158.           beq.s    1$
  159.           jsr      _LVOClose(a6)         ; Chiude fileaperto
  160.  
  161. 1$        move.l   execbase(a5),a6
  162.           move.l   port(a5),d0
  163.           tst.l    d0
  164.           beq.s    2$
  165.           move.l   d0,a1
  166.           bsr      DeletePort            ; Cancella eventuale porta
  167. 2$        move.l   mementry(a5),d0
  168.           tst.l    d0
  169.           beq.s    3$
  170.           move.l   d0,a0
  171.           jsr      _LVOFreeEntry(a6)     ; Cancella eventuali allocazioni
  172. 3$        move.l   dosbase(a5),a1
  173.           jsr      _LVOCloseLibrary(a6)  ; Chiude DOS.library
  174.           rts
  175.  
  176. MemErr:
  177.           lea      MemMess(pc),a0
  178.           move.l   a0,d2
  179.           moveq    #47,d3
  180.           bra.s    Err
  181. Error:
  182. CLIErr:
  183.           lea      CLIMess(pc),a0
  184.           move.l   a0,d2
  185.           moveq    #36,d3
  186.           bra.s    Err
  187. ReadErr:  lea      ReadMess(pc),a0
  188.           move.l   a0,d2
  189.           moveq    #36,d3
  190.           bra.s    Err
  191. WriteErr:
  192.           lea      WriteMess(pc),a0
  193.           move.l   a0,d2
  194.           moveq    #28,d3
  195.           bra.s    Err
  196. OpenErr:
  197.           lea      OpenMess(pc),a0
  198.           move.l   a0,d2
  199.           moveq    #25,d3
  200.           bra.s    Err
  201. PError:
  202.           lea      PMess(pc),a0
  203.           move.l   a0,d2
  204.           moveq    #41,d3
  205.           bra.s    Err
  206. TErr
  207.           lea      TMess(pc),a0
  208.           move.l   a0,d2
  209.           moveq    #39,d3
  210. Err       move.l   stdout(a5),d1
  211.           tst.l    d1
  212.           beq      Fin               ; Se manca stream di output
  213.           move.l   dosbase(a5),a6
  214.           jsr      _LVOWrite(a6)
  215.           bra      Fin
  216.  
  217. CreatePort:
  218.           move.l   a2,-(a7)
  219.           move.l   mementry(a5),a2
  220.           add.w    #Mem3-Mem,a2
  221.           move.l   (a2),a2
  222.           moveq    #-1,d0
  223.           jsr      _LVOAllocSignal(a6)
  224.           moveq    #-1,d1
  225.           cmp.l    d0,d1         ; -1 indica "segnale scorretto"
  226.           bne.s    cp_sigok
  227.           move.l   (a7)+,a2
  228.           moveq    #0,d0        ; Indica altrimenti "nessuna porta"
  229.           rts
  230. cp_sigok:
  231.           move.b   d0,MP_SIGBIT(a2)
  232.           move.b   #PA_SIGNAL,MP_FLAGS(a2)
  233.           move.b   #NT_MSGPORT,LN_TYPE(a2)
  234.           clr.b    LN_PRI(a2)
  235.           move.l   task(a5),d0
  236.           move.l   d0,MP_SIGTASK(a2)
  237.           lea.l    MP_MSGLIST(a2),a0  ; Punta a header di lista
  238.           NEWLIST  a0         ; Inizializza nuova lista macro
  239.           move.l   a2,d0
  240.           move.l   (a7)+,a2   ; cc's NOT influenzato
  241.           rts
  242.  
  243. DeletePort:
  244.           moveq    #-1,d0
  245.           move.b   d0,LN_TYPE(a1)
  246.           move.l   d0,MP_MSGLIST+LH_HEAD(a1)
  247.           moveq    #0,d0
  248.           move.b   MP_SIGBIT(a1),d0
  249.           jsr      _LVOFreeSignal(a6)
  250.           rts
  251.  
  252. table:
  253.           dc.l     $3f3        ; Hunk_Header
  254.           dc.l     0           ; Nessun Hunk_Name
  255.           dc.l     1           ; Dimensione Hunk table
  256.           dc.l     0           ; Primo hunk
  257.           dc.l     0           ; Ultimo hunk
  258.           dc.l     256         ; Numero di longwords in hunk
  259.           dc.l     $3e9        ; Hunk_Code
  260.           dc.l     256         ; Numero di longword nell'hunk
  261.  
  262. hunkend
  263.           dc.l     $3f2        ; Hunk_End
  264.  
  265. BASE:
  266. Dosbase     dc.l  0
  267. Execbase    dc.l  0
  268. Filehandle  dc.l  0
  269. Buffer      dc.l  0
  270. Port        dc.l  0
  271. FileName    dc.l  0
  272. DiskReq     dc.l  0
  273. Task        dc.l  0
  274. MemEntry    dc.l  0
  275. Unit        dc.l  0
  276. Stdout      dc.l  0
  277.  
  278. Mem         ds.b  LN_SIZE
  279.             dc.w  3
  280. Mem1        dc.l  MEMF_CHIP!MEMF_CLEAR
  281.             dc.l  1024
  282. Mem2        dc.l  MEMF_PUBLIC!MEMF_CLEAR
  283.             dc.l  IOSTD_SIZE
  284. Mem3        dc.l  MEMF_PUBLIC!MEMF_CLEAR
  285.             dc.l  MP_SIZE
  286.  
  287. DosLib      dc.b  'dos.library',0
  288. TrackName   dc.b  'trackdisk.device',0
  289. MemMess     dc.b  'Not enough Memory to allocate required buffers',10
  290. CLIMess     dc.b  'Usage:  FileBootBlock df?: filename',10
  291. ReadMess    dc.b  'Disk Error while reading Boot Block',10
  292. WriteMess   dc.b  'Error while writing to file',10
  293. OpenMess    dc.b  'Error while opening file',10
  294. PMess       dc.b  'Couldn''t create message port for disk IO',10
  295. TMess       dc.b  'Couldn''t get access to specified drive',10
  296.  
  297.       end
  298.